<template>
	<view class="pri-box" ref='refBox'>
		<web-view :src="webUrl" ref='refWeb' @message="handleMessage"></web-view>
		<view class="pri-btn" v-if="type != 'hide'">
			<a class="btn" :class="{'pri-ba': canLogin == 'can'}" @click="btnPri">read and agree</a>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:"",
				webUrl: '',
				canLogin:"not"
			};
		},

		onLoad(option) {
			const webUrl = uni.getStorageSync('webUrl') || this.COFIG?.staticUrl; //默认先取缓存中存储的上次可以访问的域名
			const lastStr = webUrl.slice(-1);//判断域名是否带斜杠/
			const privacyPage = lastStr == "/" ? "privacy.html" : "/privacy.html"
			this.webUrl = webUrl + privacyPage
			this.canLogin = uni.getStorageSync('canLogin') || "not"
			this.type = option?.type || ""
		},
		
		onReady(){
			let height = 0; //定义动态的高度变量
			let statusbar = 0; // 动态状态栏高度
			uni.getSystemInfo({ // 获取当前设备的具体信息
				success: (sysinfo) => {
					statusbar = sysinfo.statusBarHeight;
					height = sysinfo.windowHeight;
				}
			});
			let currentWebview = this.$scope.$getAppWebview(); //获取当前web-view
			setTimeout(function() {
				var wv = currentWebview.children()[0];
				wv.setStyle({ //设置web-view距离顶部的距离以及自己的高度，单位为px
					top: statusbar + 44, //此处是距离顶部的高度，应该是你页面的头部
					height: height - statusbar, //webview的高度,减去状态栏
				})
			}, 200); //如页面初始化调用需要写延迟
		},
		
		methods: {
			handleMessage(evt) {
				let obj = evt?.detail?.data;
				if (obj[0].action == "toBottom") {
					try {
						this.canLogin = "can";
						uni.setStorageSync('canLogin',this.canLogin);
					} catch (e) {
			
					}
				}
			},
			
			btnPri(){
				if(this.canLogin == "can"){
					uni.navigateBack({
						delta: 1
					})
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.pri-box{
		position: relative;
		display: flex;
		justify-content: center;
		align-items: flex-end;
		width: 100%;
		height: 100vh;
	}
	.pri-btn{ position: absolute;bottom:0;height: 90rpx;line-height:90rpx ;}
	.pri-btn a{ width: 500rpx; height: 60rpx; background-color: #6580FA;line-height: 60rpx; text-align: center; font-size: 30rpx; color: #FFF; background-color: #dedede; border-radius: 10rpx; display: block; margin: 20rpx auto 0 auto;}
	.pri-btn .pri-ba{ background-color: #6580FA;}
</style>